package com.polytech.web.client.service;

import java.util.List;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.polytech.web.client.model.Person;
import com.polytech.web.client.table.DataSource;
import com.polytech.web.client.table.MyTable;

public class PersonCallback implements AsyncCallback<List<Person>> {

	private MyTable table;

	public PersonCallback(MyTable table) {
		this.table = table;
	}

	public void onFailure(Throwable caught) {
		Window.alert(caught.getMessage());
	}

	public void onSuccess(List<Person> result) {
		if (result != null) {
			List<Person> users = result;
			if (users != null) {
				DataSource datasource = new DataSource(users);
				table.setInput(datasource);
				for (Person user : users) {
					System.out.println(user.getUsername());
					System.out.println(user.getUserLastname());
				}
			}
		}
	}

}
